home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_04 / letters / round.c < prev    next >
C/C++ Source or Header  |  1994-01-20  |  824b  |  25 lines

  1. @CSOURCE8 = #include <<math.h>><R>
  2. extern double round_cent (double);<R>
  3. <R>
  4. #define SMALLNUM .00000000001  /*super small number (100's)*/<R>
  5.         /*(smallnum is added to a double before truncating to an integer<R>
  6.           to ensure that a number like 5.99999999999999999 is really 
  7. 6.0)<R>
  8.          */<R>
  9. <R>
  10. double round_cent (num)<R>
  11. /*     round_cent rounds a number to the cents place (round to .01).*/<R>
  12. double num; /*number to round*/<R>
  13. {<R>
  14.        double tdoub; /*temporary double*/<R>
  15. <R>
  16.        tdoub = num * 100.0 + .5 + SMALLNUM;   /*move num to left<R>
  17.                                                 and add .50000000001 
  18. for rounding*/<R>
  19.        tdoub = floor (tdoub); /*drop decimals*/<R>
  20.        return (tdoub * .01); /*move num back to right*/<R>
  21. }<R>
  22. <R>
  23. /* End of File */ 
  24.  
  25.